package com.github.willisaway.core.util;

import java.math.BigDecimal;
import java.util.Comparator;
import java.util.Date;
import java.util.Map;

public class ComparatorMap<T extends Comparable> implements Comparator<Map> {
    boolean isAsc;
    String sortKey;

    public ComparatorMap(String sortKey) {
        this.isAsc = true;// 默认是升序
        this.sortKey = sortKey;
    }

    public ComparatorMap(boolean isAsc, String sortKey) {
        this.isAsc = isAsc;
        this.sortKey = sortKey;
    }

    public int compare(Map map1, Map map2) {
        T data1 = (T) map1.get(sortKey);
        T data2 = (T) map2.get(sortKey);
        int iResult = 0;
        if (isAsc) {
            iResult = data1.compareTo(data2);
        } else {
            iResult = data2.compareTo(data1);
        }
        return iResult;
    }
}
